package com.example.appmanager.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.appmanager.Appconfig.Appconfig;
import com.example.appmanager.R;
import com.example.appmanager.entity.DetailsEntity;
import com.example.appmanager.entity.UserReview;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/*用户评论的适配器 对应的comments_layout.xml*/
public class CommentsAdapter extends RecyclerView.Adapter<CommentsAdapter.CommentViewHolder> {

    private Context context;
    private List<UserReview.RowsBean> rowsBeans = new ArrayList<>();

    public CommentsAdapter(Context context, List<UserReview.RowsBean> rowsBeans) {
        this.context = context;
        this.rowsBeans = rowsBeans;
    }
    public CommentsAdapter() {
    }
    public void setData(Context context, List<UserReview.RowsBean> rowsBeans) {
        this.context = context;
        this.rowsBeans = rowsBeans;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public CommentViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.comments, parent, false);
        return  new CommentViewHolder(view);

    }
    @Override
    public void onBindViewHolder(@NonNull CommentViewHolder holder, int position) {

        Glide.with(context).load(Appconfig.BASE_IMAG+rowsBeans.get(position).getPicture()).into(holder.imageViewUser);
        holder.textViewUserName.setText(rowsBeans.get(position).getUname());
        holder.textViewComments.setText(rowsBeans.get(position).getRmessage());
    }

    @Override
    public int getItemCount() {
        return rowsBeans==null?0:rowsBeans.size();
    }
    public class  CommentViewHolder extends RecyclerView.ViewHolder{

        private ImageView imageViewUser;//用户头像
        private ImageView imageViewComments;//评论
        private TextView   textViewUserName;//
        private TextView  textViewComments;//
        public CommentViewHolder(@NonNull View itemView) {
            super(itemView);
            imageViewUser = itemView.findViewById(R.id.imageView_user);//用户头像
            imageViewComments = itemView.findViewById(R.id.imageView_comments);//评论
            textViewUserName = itemView.findViewById(R.id.textView_user_name);//
            textViewComments = itemView.findViewById(R.id.textView_comments);//

        }
    }
}
